package com.member.mp.web;

import com.member.common.core.domain.AjaxResult;
import com.member.common.utils.ObsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 【通用】请求处理
 *
 * @author wangxin
 */
@Api(value = "公共接口", tags = {"公共接口"})
@RestController
@RequestMapping("/wx/common/obs")
public class CommonObsController {
    @Resource
    private ObsUtil obsUtil;

    /**
     * 通用上传请求（单个）
     */
    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) {
        try {
            Map<String, String> map = obsUtil.upload(file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("url", map.get("url"));
            ajax.put("fileName", map.get("originalFilename"));
            return ajax;
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }

    }

}
